<?php
	function getCategories(){
		global $db;
		$query = 'SELECT * FROM categories ORDER BY id';
		$statement = $db->prepare($query);
		$statement->execute();
		$categories = $statement->fetchAll();
		
		return $categories;
	}
	
	function getCategoriesNames(){
		global $db;
		$query = 'SELECT `name` FROM categories ORDER BY id';
		$statement = $db->prepare($query);
		$statement->execute();
		$categories = $statement->fetchAll();
		
		return $categories;
	}
	
	function getCategoryName($category_id){
		global $db;
		$query = 'SELECT `name` FROM categories WHERE íd = $category_id';
		$statement = $db->prepare($query);
		$statement->execute();
		$category_name = $statement->fetch();
		
		return $category_name;
	}

	function addCategory($name){
		global $db;

		$query = "INSERT INTO categories (name) VALUES (:name)";
		$statement = $db->prepare($query);
		$statement->bindValue(':name', filter_var($name,FILTER_SANITIZE_STRING));

		$statement->execute();
	}

	function deleteCategory($category_id){
		global $db;
		$query = "DELETE FROM categories WHERE id = $id";
		$db->exec($query);

		$query = 'DELETE FROM menu WHERE id = $category_id';
		$db->exec($query);
	}
?>